home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: operator % - compiler error
- Date: Mon, 18 Mar 96 13:54:11 GMT
- Organization: none
- Message-ID: <827157251snz@genesis.demon.co.uk>
- References: <4ihuuh$6ul@hatathli.csulb.edu>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: relay-4.mail.demon.net!post.demon.co.uk!genesis.demon.co.uk
-
- In article <4ihuuh$6ul@hatathli.csulb.edu> davidcho@csulb.edu "David Cho" writes:
-
- >When I try to compile, I get an erro message for the following line:
- >
- >
- >
- >x=663608941*y%pow(2,32) /*I want remainder*/
- >
- >But the error message says "illegal use of floating point". What does
- >that mean? Isn't % used a an operator to calcuate the remainder?
-
- Yes, it calcuates integer remainder and it requires its operands to be
- integers. pow() returns a double result which is not suitable. You need to
- provide more information about what you want to do. There is no guarantee
- that any C inreger type can hold 2 to the power of 32. You need to be clear
- about what types x and y have - it looks like they need to be unsigned long
- here to avoid overflow problems. Maybe what you need is:
-
- x = (663608941 * y) & 0xffffffff;
-
- which also avoids a costly and potentially inaccurate mathematical function.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-